namespace Bookvar.ObjectModel.Actions
{
    public class ChangeTopicPositionAction : MindmapTopicActionBase
    {
        public TopicPosition NewPosition { get; set; }
        private readonly TopicPosition oldPosition;
        private readonly TopicPosition newPosition;

        public ChangeTopicPositionAction( Topic topic, TopicPosition newPosition, MindMap mindmap )
            : base( topic, mindmap )
        {
            NewPosition = newPosition;

            //clone the positions, because we are going to update them
            oldPosition = mindmap.TopicPositions[ topic.ID ].Clone();
            this.newPosition = newPosition;
        }

        public override void Execute()
        {
            base.Execute();

            var position = Mindmap.TopicPositions[ Topic.ID ];

            position.X = newPosition.X;
            position.Y = newPosition.Y;
            position.IsMoved = newPosition.IsMoved;
        }

        public override void Undo()
        {
            base.Undo();

            var position = Mindmap.TopicPositions[ Topic.ID ];

            position.X = oldPosition.X;
            position.Y = oldPosition.Y;
            position.IsMoved = oldPosition.IsMoved;
        }
    }
}